import request from '@/utils/request'
import config from '@/utils/config'
// 登录方法
export function login(username, password) {
  if (config.isLocal) {
    return new Promise(resolve => {
      resolve({
        code: 200,
        msg: '成功',
        token: 'admin-token'
      })
    })
  } else {
    const data = {
      username,
      password
    }
    return request({
      url: '/login',
      headers: {
        isToken: false
      },
      method: 'post',
      data: data
    })
  }
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export function getInfo() {
  if (config.isLocal) {
    return new Promise(resolve => {
      resolve({ "msg": "操作成功", "code": 200, "permissions": ["*:*:*"], "roles": ["admin"], "user": { "createBy": "admin", "createTime": "2023-02-03 11:11:26", "updateBy": null, "updateTime": null, "remark": "管理员", "userId": 1, "deptId": 103, "userName": "admin", "nickName": "若依", "email": "ry@163.com", "phonenumber": "15888888888", "sex": "1", "avatar": "", "password": "$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2", "status": "0", "delFlag": "0", "loginIp": "110.228.41.182", "loginDate": "2023-03-22T22:30:18.000+08:00", "dept": { "createBy": null, "createTime": null, "updateBy": null, "updateTime": null, "remark": null, "deptId": 103, "parentId": 101, "ancestors": "0,100,101", "deptName": "研发部门", "orderNum": 1, "leader": "若依", "phone": null, "email": null, "status": "0", "delFlag": null, "parentName": null, "children": [] }, "roles": [{ "createBy": null, "createTime": null, "updateBy": null, "updateTime": null, "remark": null, "roleId": 1, "roleName": "超级管理员", "roleKey": "admin", "roleSort": 1, "dataScope": "1", "menuCheckStrictly": false, "deptCheckStrictly": false, "status": "0", "delFlag": null, "flag": false, "menuIds": null, "deptIds": null, "permissions": null, "admin": true }], "roleIds": null, "postIds": null, "roleId": null, "admin": true } })
    })
  } else {
    return request({
      url: '/getInfo',
      method: 'get'
    })
  }


}

// 退出方法
export function logout() {
  // return request({
  //   url: '/logout',
  //   method: 'post'
  // })
  return new Promise(resolve => {
    resolve({ "msg": "操作成功", "code": 200 })
  })
}
